

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileDelete {

	public static void main(String[] args) {
		File file=new File("E:\\2012\\workspace\\wlzxCourseSelective\\WebContent");
		long begin=System.currentTimeMillis();
		List<String> deletePaths=new ArrayList<String>();//存储待删除文件路径
		for(File tmp:file.listFiles()){
			dealFile(tmp,deletePaths);
		}
		for(String path:deletePaths){
			File deletePath=new File(path);
			deleteSubFile(deletePath);
		}
		long end=System.currentTimeMillis();
		System.out.println(end-begin);
		System.out.println((4/3.0<=2*1.0));
		//deleteSameFile(file);
	}
	//递归函数-筛选出待删除文件
	public static void dealFile(File file,List<String> deletePaths){
		if(file.isDirectory()){
			if(file.getName().equals(".svn")){
				deletePaths.add(file.getAbsolutePath());
			}else{
				for(File tmp:file.listFiles()){
					dealFile(tmp,deletePaths);
				}
			}
		}else return ;
	}
	//递归函数-删除文件夹及子文件
	public static void deleteSubFile(File file){
		if(file.listFiles().length==0)
			file.delete();
		else{
			for(File tmp:file.listFiles()){
				if(tmp.isFile())
					tmp.delete();
				else deleteSubFile(tmp);
			}
			file.delete();
		}
	}
	public static void deleteSameFile(File file){
		List<String> deletePaths=new ArrayList<String>();//存储待删除文件路径
		if(file.isDirectory()){
			for(File subFile:file.listFiles()){
				if(subFile.isDirectory()&&(subFile.getName().equals("oa")||subFile.getName().equals("basic")||subFile.getName().equals("system"))){
					for(File tmp:subFile.listFiles()){
						if(tmp.isFile()){
							if(tmp.getName().equals("framework_4.5.1.21328.swz")||tmp.getName().equals("mx_4.5.1.21328.swz")||tmp.getName().equals("rpc_4.5.1.21328.swz")||tmp.getName().equals("spark_4.5.1.21328.swz")||tmp.getName().equals("sparkskins_4.5.1.21328.swz")||tmp.getName().equals("textLayout_2.0.0.232.swz"))
								deletePaths.add(tmp.getAbsolutePath());
						}else if(tmp.isDirectory()){
							for(File tmp2:tmp.listFiles()){
								if(tmp2.isFile()){
									if(tmp2.getName().equals("framework_4.5.1.21328.swz")||tmp2.getName().equals("mx_4.5.1.21328.swz")||tmp2.getName().equals("rpc_4.5.1.21328.swz")||tmp2.getName().equals("spark_4.5.1.21328.swz")||tmp2.getName().equals("sparkskins_4.5.1.21328.swz")||tmp2.getName().equals("textLayout_2.0.0.232.swz"))
										deletePaths.add(tmp2.getAbsolutePath());
								}
							}
						}
					}
				
				}
			
			}
		}
		System.out.println(deletePaths.size());
		for(String path:deletePaths){
			File deletePath=new File(path);
			deletePath.delete();
		}
	}
	
}